package com.ijuit.model.user;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
/**
 * 用户信息主表
 * @author 罗龙
 *
 *  用户信息表结构
 *  +-----------------+--------------+------+-----+---------+----------------+
	| Field           | Type         | Null | Key | Default | Extra          |
	+-----------------+--------------+------+-----+---------+----------------+
	| id              | int(11)      | NO   | PRI | NULL    | auto_increment |
	| loginId         | varchar(30)  | NO   |     |         |                |
	| password        | varchar(50)  | NO   |     |         |                |
	| mobileTelephone | varchar(20)  | NO   |     |         |                |
	| email           | varchar(100) | YES  |     |         |                |
	| name            | varchar(20)  | YES  |     |         |                |
	| address         | varchar(100) | YES  |     |         |                |
	| actflag         | tinyint(4)   | YES  |     | 1       |                |
	| createTime      | varchar(20)  | NO   |     |         |                |
	+-----------------+--------------+------+-----+---------+----------------+
 *createTime
 */
public class User extends Model<User>{
	
	private static final long serialVersionUID = 1L;
	
	public static final User me = new User();
	/**
	 * 分页获取用户信息列表
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	public Page<User> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select *", "from user order by id asc");
	}
	
	/**
	 * 根据登陆账号密码获取用户id
	 * @param loginId
	 * @param password
	 * @return
	 */
	public int getByLoginId(String loginId, String password){
		int rvalue = 0;
		User user = findFirst("SELECT id FROM user WHERE (loginId=? OR mobileTelephone=? OR email=?) AND password=?",loginId,loginId,loginId,password);
		if(user!=null){
			rvalue = user.getInt("id");
		}
		return rvalue;
	}
	
	/**
	 * 查看用户是否存在
	 * @param loginId
	 * @return
	 */
	public boolean exist(String loginId){
		boolean rvalue = false;
		User user = findFirst("SELECT id FROM user WHERE loginId=? OR mobileTelephone=? OR email=?",loginId,loginId,loginId);
		if(user == null){
			rvalue = true;
		}
		return rvalue;
	}
}
